//---------------Sonic CD Block Script---------------//
//-------Scripted by Christian Whitehead--------//

// Aliases
#alias Object.Value0	:	Object.Timer
#alias Object.Value1	:	Object.XVelocity
#alias Object.Value2	:	Object.YVelocity
#alias Object.Value3	:	Object.GoTimer
#alias Object.Value4	:	
#alias Object.Value5	:	
#alias Object.Value6	:	Object.GoTimer

#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod

#alias Object.PropertyValue		:	PushButton.Pressed	

// Global SFX
#alias 22	:	SFX_G_EXPLOSION

// Gravity Modes
#alias 1	:	GRAVITY_AIR

// ========================
// Subs
// ========================

sub ObjectMain
	if PushButton[-2].Pressed == true
		Object.Value4 = 1
	end if

	GetBit(TempValue0, object.propertyValue, 1)

	if TempValue0 == 0

		object.Timer--

		if object.Timer <= 0

			if object.XVelocity == 0
				// how long it stays off
				object.Timer = 150
			else
				// how long it stays on
				object.Timer = 210
				if Object.OutofBounds == false
				//	PlayStageSFX(9, false)
				end if
			end if

			object.XVelocity ^= 1

		end if
	end if

	if object.XVelocity == 0
		if Object.Frame > 2
			Object.Frame = 0
		else
			Object.Frame++
		end if

		if Object.Value6 == 1
			Object.Value5 -= 4

			if Object.Value5 <= 0
				Object.Value6 = 0
			end if

		else
			Object.Value5 += 4

			if Object.Value5 > 80
				Object.Value6 = 1
			end if

		end if

		TempValue0 -= Object.Value5
		TempValue0 -= 364
	end if
end sub

sub ObjectPlayerInteraction
	if object.XVelocity == 0
		PlayerObjectCollision(C_TOUCH, -32, -8, 32, 8)
		if CheckResult == true
			CallFunction(Player_Hit)
		end if
		
		PlayerObjectCollision(C_TOUCH, -56, -384, 56, 0)
		if CheckResult == true
			//player.animation 		= ANI_JUMPING
			Player.Animation 		= ANI_FANROTATE
			player.state 			= Player_State_Air
			player.gravity 			= 1
			player.tileCollisions 	= true
			player.speed 			= player.xvelocity
			player.timer 			= 0
			player.yvelocity 		= 0

			TempValue0 <<= 16
			TempValue0 += object.ypos
			TempValue0 -= player.ypos
			TempValue0 >>= 6
			player.ypos += TempValue0
			
		end if
	end if
end sub

sub ObjectDraw
	DrawSprite(Object.Frame)
end sub

sub ObjectStartup
	LoadSpriteSheet("R2/Objects3.gif")		
	SpriteFrame(-47, -6, 94, 12, 69, 52)	// #0 Fan
	SpriteFrame(-47, -6, 94, 12, 69, 78)	// #1 Fan
	SpriteFrame(-47, -6, 94, 12, 69, 104)	// #2 Fan
		
	SpriteFrame(-47, -6, 94, 12, 69, 78)	// #1 Fan
	SpriteFrame(-47, -6, 94, 12, 69, 52)	// #0 Fan

	ArrayPos0 = 32
	while ArrayPos0 < 1056
		if Object[ArrayPos0].Type == TypeName[Fan]
			Object[ArrayPos0].Priority = 1
		end if
		ArrayPos0++
	loop

end sub

// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
	
	if editor.showGizmos == true
		editor.drawingOverlay = true

		TempValue0 = object.ypos
		TempValue0 -= 0x100 0000
		DrawArrow(object.xpos, object.ypos, object.xpos, TempValue0, 255, 255, 255)
		
		editor.drawingOverlay = false
	end if
end sub


sub RSDKLoad
	LoadSpriteSheet("R2/Objects3.gif")
	SpriteFrame(-47, -6, 94, 12, 69, 117)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub